#!/usr/bin/perl

# This is a proof of concept for cleaning up the imported functions.
#
# The clue is to use constants which are available at compilaton-time and
# not available at run-time
#
# Unfortunately, the functions have to be called as coderef and then
# don't support prototypes.

# Inlined package
BEGIN {

    package MyClass;

    # import function
    use Scalar::Util "looks_like_number";

    # reimport it into temporary namespace
    BEGIN {
        *tmp::looks_like_number = \&looks_like_number;
        undef *looks_like_number;
    };

    # redeclare it as coderef constant
    use constant looks_like_number => \&tmp::looks_like_number;

    # my method
    sub is_num {
        my ($self, $val) = @_;
        # the constant is available at compilation-time
        looks_like_number->("$val");
    };

    # delete constant from namespace
    undef *looks_like_number;

    $INC{'MyClass.pm'} = __FILE__;
};


use MyClass;

use YAML ();
use Class::Inspector ();

# use method which calls imported function
print YAML::Dump {
    'is_num(42)' => MyClass->is_num(42),
    'is_num("string")' => MyClass->is_num("string"),
};

# dumps out all functions and methods of my class
print YAML::Dump {
    'Class::Inspector->functions("MyClass")' => Class::Inspector->functions("MyClass"),
    'Class::Inspector->methods("MyClass")' => Class::Inspector->methods("MyClass"),
};

# die with error: the constant is not available at run-time
print MyClass->looks_like_number;

__END__

The suspected output is:

---
is_num("string"): 0
is_num(42): 1
---
Class::Inspector->functions("MyClass"):
  - is_num
Class::Inspector->methods("MyClass"):
  - is_num
Can't locate object method "looks_like_number" via package "MyClass" at proof_of_concept.pl line 60.
